﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Spyfall.Managers
{   
    class MessageManager
    {
        private static MessageManager s_Instance;

        public static MessageManager GetInstance
        {
            get
            {
                if (s_Instance == null)
                    s_Instance = new MessageManager();
                return s_Instance;
            }
        }

        public delegate void MESSAGEPROC(Spyfall.Messages.Message msg);
        private MESSAGEPROC messageProc;
        private Queue<Messages.Message> msgQueue;

        public void Init(MESSAGEPROC msgFunc) 
        {
            messageProc = msgFunc;
            msgQueue = new Queue<Messages.Message>();
        }

        public void SendMessage(Messages.Message msg)
        {
            msgQueue.Enqueue(msg);
        }

        public void ClearMessages()
        {
            msgQueue.Clear();
        }

        public void ProcessMessages()
        {
           for(int i = 0; i < msgQueue.Count; i++)
                messageProc(msgQueue.Dequeue());
        }
    }
}
